package com.lagou.edu.service;

import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import javax.validation.constraints.Size;
import java.util.Date;

/**
 * @ClassName EmailService
 * @Description TODO
 * @Auth ying.xiao
 * @Date 2021/4/20
 * @Version 1.0.0
 */
@Service
@Slf4j
public class EmailService implements service.EmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public boolean sendEmail(String email,String code){
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setSubject("验证码邮件");
            message.setFrom("1832943940@qq.com");
            message.setTo(email);
            message.setSentDate(new Date());
            message.setText("你离注册成功还剩最后一步，尽情地去输入你的验证码吧："+code);
            javaMailSender.send(message);
        }catch (Exception e){
            log.error("send email error");
            return false;
        }
        return true;
    }
}
